package libraries;

import java.io.File;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.text.ParseException;

import javax.swing.ImageIcon;
import javax.swing.JFrame;

import GUI.BDPacienteSave;
import GUI.InterPacienteSave;
import java.sql.Time;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.tree.DefaultMutableTreeNode;


public class FunctionLibrary extends JFrame{
    Connection o;
    PreparedStatement s;
    InterPacienteSave IPS = new BDPacienteSave();
    
    
    public FunctionLibrary() {

    }

    public String pathRaiz(){
        File raiz;
        raiz = new File("");
        String path = raiz.getAbsolutePath();
        System.out.println("PATH: "+path);
        path = path.concat("//");
        return path;
    }
    public String eyeTranslation(String ImageLaterality){
        String eye = null;
        if(ImageLaterality.equals("L")){eye = "OI";}
        else if(ImageLaterality.equals("R")){eye = "OD";}
        else if(ImageLaterality.equals("B")){eye = "OI+OD";}
        else{System.out.println("ImageLaterality: "+ImageLaterality);eye = "O?";}

        return eye;
    }
    public void addNodeInSortedOrder(DefaultMutableTreeNode parent, DefaultMutableTreeNode child){
           int n = parent.getChildCount();
           if(n==0){
               parent.add(child);
               return;
           }
           DefaultMutableTreeNode node=null;
           for(int i=0;i<n;i++){
               node = (DefaultMutableTreeNode)parent.getChildAt(i);
               if(node.toString().compareTo(child.toString())>0){
                   parent.insert(child, i);
                   return;
               }
           }
           parent.add(child);
           return;
    }    
    
    public ArrayList<String> getName(String DICOMname, String separator){
        System.out.println("Entering getName function...");
        System.out.println("DICOMname: "+DICOMname);        
        ArrayList<String> result = new ArrayList();
        //String[] splitName = DICOMname.split(separator);
        int divisor = DICOMname.lastIndexOf(separator);
        String name = DICOMname.substring(divisor+1, DICOMname.length());   // Excludes the division char.
        //System.out.println("Name: "+name);
        String surNames = DICOMname.substring(0, divisor);
        surNames = surNames.replaceAll("\\"+separator, " "); // If separator is repeated eliminates it. Note: if separator is an special character put '\\'.
        System.out.println("SurNames: "+surNames);
        
        result.add(name);       // Add Name.
        result.add(surNames);   // Add SurNames.
        System.out.println("Resulting name from worklist: "+result.get(0)+" + "+result.get(1));
        return result;
    }
}

    
